#!/usr/bin/python3
import datetime

# 数据库字段关键字
keywords = ["status", "version", "type", "id", "user"]

# 英文字符对应的中文字符映射
symbol_mapping = {
    ":": "：",
    ";": "；",
    ",": "，",
    ".": "。",
}

# 已存在于BaseObject（BaseBO、BaseVO、BaseDTO）中的Java字段
ignore_fields = [
    "codeRefcode",
    "refcode",
    "dataStatus",
    "entityId",
    "delFlag",
    "createUser",
    "createAgentUser",
    "createDate",
    "edtid",
    "lastModUser",
    "agentUser",
    "lastModDate",
]


def check_name(name: str):
    """
    如果名称是SQL关键字，则包装为`name`，否则返回原本的name
    """
    if name in keywords:
        name = "`{}`".format(name)
    return name


def check_comment_symbol(comment: str):
    for k, v in symbol_mapping.items():
        if k in comment:
            comment = comment.replace(k, v)
    return comment


def ant_to_camel(field: str):
    if "_" in field:
        return "".join(word.title() for word in field.split("_"))
    else:
        return field.lower()


def middle_line_to_camel(field: str):
    if "-" in field:
        return "".join(word.title() for word in field.split("-"))
    else:
        return field


def entity_name(field: str):
    name = ant_to_camel(field)
    return name[:1].upper() + name[1:]


def field_name(field: str):
    field = ant_to_camel(field)
    return field[:1].lower() + field[1:]


def api_path(table_name):
    return "/api/{}".format("-".join(table_name.split("_"))).lower()


def now_str():
    current_date = datetime.datetime.now()
    formatted_date = current_date.strftime("%Y年%m月%d日 %H时%M分%S秒")
    return formatted_date
